package mlz.h_stringBuilder;

//StringBuilder的使用
public class StringBuilderDemo01 {
    public static void main(String[] args) {
        //1.创建StringBuilder对象
        StringBuilder sb = new StringBuilder();
        System.out.println("sb:" + sb );
        System.out.println("长度:" + sb.length());//长度:0

        StringBuilder sb1 = new StringBuilder("hello");
        System.out.println("sb1:" + sb1);//sb1:hello
        System.out.println("长度:" + sb1.length());//长度:5

        //2.常用方法API

        //拼接内容
        sb1.append(12);
        sb1.append("hi");
        sb1.append(true);
        System.out.println(sb1);//hello12hitrue

        //临时编程
        sb.append(12).append("hi").append("hello");
        System.out.println(sb);//12hihello

        //反转操作
        StringBuilder reverse = sb1.reverse();
        System.out.println(reverse);//eurtih21olleh

        //StringBuilder 转换成 String
        String string = sb1.toString();
        System.out.println(string);

        //String 转换成 StringBuilder -> 构造方法
        String s = "hello";
        StringBuilder builder = new StringBuilder(s);
        System.out.println(builder);


    }
}
